﻿using DevExpress.XtraReports.UI;
using Helper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;

namespace DXWinformReport
{
    public partial class report04 : DevExpress.XtraReports.UI.XtraReport
    {
        public report04()
        {
            InitializeComponent();
            DataSource = GetStudents();
            xrTableCell1.ExpressionBindings.Add(new ExpressionBinding("Text", "StuId"));
            xrTableCell2.ExpressionBindings.Add(new ExpressionBinding("Text", "StuName"));
            xrTableCell3.ExpressionBindings.Add(new ExpressionBinding("Text", "Sex"));
            xrTableCell4.ExpressionBindings.Add(new ExpressionBinding("Text", "Phone"));
        }

        private List<StudentInfo> GetStudents()
        {
            string sql = "select StuId,StuName,ClassId,Sex,Phone from StudentInfos";
            SqlDataReader dr = SqlHelper.ExecuteReader(sql, 1);
            List<StudentInfo> stuList = new List<StudentInfo>();
            while (dr.Read())
            {
                StudentInfo stu = new StudentInfo();
                stu.StuId = (int)dr["StuId"];
                stu.Sex = dr["Sex"].ToString();
                stu.Phone = dr["Phone"].ToString();
                stu.ClassId = (int)dr["ClassId"];
                stu.StuName = dr["StuName"].ToString();
                stuList.Add(stu);
            }
            dr.Close();
            return stuList;
        }

        private DataTable GetStudentsDt()
        {
            string sql = "select StuId,StuName,ClassId,Sex,Phone from StudentInfos";
            return SqlHelper.GetDataTable(sql, 1);
        }

    }
}
